package com.yanqu.road.dao.impl.activity.hanghai;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.hanghai.config.HangHaiGoodsConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class HangHaiGoodsConfigDaoImpl extends TempDao {

    public static String getHangHaiGoodsConfigMapSql = "select * from t_s_activity_hanghai_goods where activityId=?";

    public Map<Integer, HangHaiGoodsConfig> getHangHaiGoodsConfigMap(int activityId) {
        Map<Integer, HangHaiGoodsConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getHangHaiGoodsConfigMapSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HangHaiGoodsConfig hangHaiGoodsConfig = new HangHaiGoodsConfig();
                hangHaiGoodsConfig.setActivityId(rs.getInt("activityId"));
                hangHaiGoodsConfig.setGoodsId(rs.getInt("goodsId"));
                hangHaiGoodsConfig.setName(rs.getString("name"));
                hangHaiGoodsConfig.setIcon(rs.getString("icon"));
                hangHaiGoodsConfig.setBasePrice(rs.getInt("basePrice"));
                hangHaiGoodsConfig.setBaseNum(rs.getInt("baseNum"));
                map.put(hangHaiGoodsConfig.getGoodsId(), hangHaiGoodsConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
